package com.yanqu.road.server.cmd.activity.operamask;

import com.yanqu.road.logic.activity.operamask.OperaMaskSceneRankListModel;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.OperaMaskProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.activity.operamask.CrossOperaMaskMgr;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;
import com.yanqu.road.utils.YanQuMessageUtils;

@Cmd(code = CrossProtocol.C2_OPERA_MASK_START_SCENE, desc = "")
public class CrossOperaMaskStartSceneCmd extends CrossCommand {

    private int activityId;
    private int sceneId;
    private long userId;
    private long fromServerId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        OperaMaskProto.CrossOperaMaskStartSceneMsg reqMsg = OperaMaskProto.CrossOperaMaskStartSceneMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        sceneId = reqMsg.getSceneId();
        userId = packet.getPlayerId();
        fromServerId = serverId;
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        // 拿排名
        OperaMaskSceneRankListModel model = CrossOperaMaskMgr.getOperaMaskSceneRankListModel(activityId, 0, sceneId);
        int myRank = model.getMyRank(userId);

        // 返回
        OperaMaskProto.CrossOperaMaskStartSceneMsg.Builder builder = OperaMaskProto.CrossOperaMaskStartSceneMsg.newBuilder();
        builder.setActivityId(activityId);
        builder.setSceneId(sceneId);
        builder.setOldRank(myRank);
        YanQuMessage message = YanQuMessageUtils.buildMessage(GameProtocol.S_OPERA_MASK_START_SCENE_FROM_CROSS, builder);
        MessageHelper.sendPacket(fromServerId, userId, message);
    }

    @Override
    public void sendData() {

    }
}
